﻿
@{
	Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<div style="margin-left: 20px;margin-top: 20px;">
	<form class="layui-form layui-row layui-col-space16" style="width: 100%; display: flex; align-items: center;margin-top: 20px">
		<div class="layui-inline">
			<label>创建人名称</label>
			<div class="layui-inline">
				<input name="CreateName" style="width:150px;" class="layui-input" placeholder="请输入创建人名称" />
			</div>
		</div>
		<div class="layui-inline">
			<button class="layui-btn layui-bg-blue" lay-submit lay-filter="demo-table-search">查询</button>

			<button type="reset" class="layui-btn layui-btn-primary">清除</button>

			<button type="button" class="layui-btn" onclick="insertInfor()">+添加</button>
		</div>
	</form>
</div>
<div style="margin-top: 20px;margin-left: 20px">
	<table id="GetList" lay-filter="GetList"></table>
</div>
<script type="text/html" id="btn">
	<a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="upd">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>

<script>
	layui.use('table', function () {
		var table = layui.table;
		var form = layui.form;
		var laydate = layui.laydate;

		table.render({
			elem: '#GetList',
			url: '/BatchReceiving/GetBatchReceivingList',
			page: true,
			limit: 10,
			limits: [10, 20, 30],
			cols: [
				[
					{ field: 'createName', align: 'center', title: '创建人名称',width: 120 },
					{
						field: 'createDate', align: 'center', title: '创建日期', width: 180, templet: function (d) {
							return d.createDate ? layui.util.toDateString(d.createDate, 'yyyy-MM-dd') : '';
						}
					},
					{ field: 'arrivalNotice', align: 'center', title: '到货通知单',width: 120 },
					{ field: 'customerOrderNumber', align: 'center', title: '客户订单号',width: 120 },
					{ field: 'remarks', align: 'center', title: '备注',width: 100 },
					{ field: 'productCode', align: 'center', title: '商品编码',width: 100 },
					{ field: 'productName', align: 'center', title: '商品名称',width: 100 },
					{ field: 'scheduledQuantity', align: 'center', title: '预约数量',width: 100 },
					{ field: 'registeredQuantity', align: 'center', title: '已登记数量',width: 120 },
					{ field: 'unreceivedQuantity', align: 'center', title: '未收货数量' ,width: 120},
					{
						field: 'productionDate', align: 'center', title: '生产日期',width: 180, templet: function (d) {
							return d.productionDate ? layui.util.toDateString(d.productionDate, 'yyyy-MM-dd') : '';
						}
					},
					{ field: 'batchNumber', align: 'center', title: '批次',width: 100 },
					{ field: 'storageLocation', align: 'center', title: '储位',width: 100  },
					{ field: 'palletNumber', align: 'center', title: '托盘',width: 100  },
					{ field: 'unit', align: 'center', title: '单位',width: 100  },

					{ title: '操作', fixed: 'right', width: 200, align: 'center', toolbar: '#btn' }
				]
			],
			done: function (res, curr, count) {
				//console.log(curr);
			}
		});

		form.on('submit(demo-table-search)', function (data) {
			var field = data.field;
			$.ajax({
				type: 'get',
				url: '/BatchReceiving/GetBatchReceivingList',
				data: field,
				success: function (res) {
					console.log(res);
					table.reload('GetList', {
						page: { curr: 1 },
						where: field
					});
					layer.msg('搜索成功');
				},
				error: function (err) {
					console.error('搜索失败', err);
					layer.msg('搜索失败，请稍后重试');
				}
			});
			return false;
		});

				table.on('tool(GetList)', function (obj) {
				var data = obj.data;
				console.log(data.id);

				if (obj.event === 'delete') {
					layer.confirm('确定要删除吗？', function (index) {
						var data = obj.data;
						$.ajax({
								url: "/BatchReceiving/DeleteBatchReceiving",
							type: "get",
							data: {
								id: data.id
							},
							success: function (res) {
								console.log(res);
								if (res === 1) {
									layer.msg('删除成功');
										table.reload('GetList');
								} else {
									layer.msg('删除失败: ' + res.msg);
								}
							},
							error: function (xhr, status, error) {
								console.error('删除请求出错', error);
								layer.msg('删除请求出错，请重试');
							}
						});

						layer.close(index);
					});
				}
				if (obj.event === 'upd') {
					layer.open({
						type: 2,
							title: '编辑批量收货',
						shadeClose: true,
						shade: 0.5,
						area: ['1000px', '80%'],
							content: ['/BatchReceiving/Update?id=' + data.id, 'no'],
						end: function () {
							location.reload();
						}
					});
				}
			})
		});

		function insertInfor() {
			layer.open({
				type: 2,
				title: '批量收货',
				shadeClose: true,
				shade: 0.5,
				area: ['1000px', '80%'],
					content: '/BatchReceiving/Add',
				end: function () {
					location.reload();
				}
			});
		}
</script>

